package com.finer.service.impl;

import com.finer.dao.FinerSaleBackDetailDao;
import com.finer.entity.sell.FinerSaleBackDetail;
import com.finer.service.FinerSaleBackDetailService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 销售退货详情表(FinerSaleBackDetail)表服务实现类
 *
 * @author makejava
 * @since 2024-10-21 10:20:39
 */
@Service("finerSaleBackDetailService")
public class FinerSaleBackDetailServiceImpl implements FinerSaleBackDetailService {
    @Resource
    private FinerSaleBackDetailDao finerSaleBackDetailDao;

    /**
     * 通过ID查询单条数据
     *
     * @param Id 主键
     * @return 实例对象
     */
    @Override
    public FinerSaleBackDetail queryById(Integer Id) {
        return this.finerSaleBackDetailDao.queryById(Id);
    }

    /**
     * 分页查询
     *
     * @param finerSaleBackDetail 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<FinerSaleBackDetail> queryByPage(FinerSaleBackDetail finerSaleBackDetail, PageRequest pageRequest) {
        long total = this.finerSaleBackDetailDao.count(finerSaleBackDetail);
        return new PageImpl<>(this.finerSaleBackDetailDao.queryAllByLimit(finerSaleBackDetail, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param finerSaleBackDetail 实例对象
     * @return 实例对象
     */
    @Override
    public FinerSaleBackDetail insert(FinerSaleBackDetail finerSaleBackDetail) {
        this.finerSaleBackDetailDao.insert(finerSaleBackDetail);
        return finerSaleBackDetail;
    }

    /**
     * 修改数据
     *
     * @param finerSaleBackDetail 实例对象
     * @return 实例对象
     */
    @Override
    public FinerSaleBackDetail update(FinerSaleBackDetail finerSaleBackDetail) {
        this.finerSaleBackDetailDao.update(finerSaleBackDetail);
        return this.queryById(finerSaleBackDetail.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param Id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer Id) {
        return this.finerSaleBackDetailDao.deleteById(Id) > 0;
    }
}
